Skip to content

Add Custom Identity User and Modify Registration/login#16

Merged
JoeProgrammer88 merged 8 commits intomainfrom
CustomizeIdentityUser
Oct 3, 2025
Merged

Add Custom Identity User and Modify Registration/login#16
JoeProgrammer88 merged 8 commits intomainfrom
CustomizeIdentityUser

Conversation

@JoeProgrammer88
Copy link
Copy Markdown
Member

This pull request configures registration and login functionality using ASP.NET Core Identity, including customized registration and login pages, and integrates the custom ApplicationUser model with additional properties. The changes also updated the Entity Framework context to support the new user model.

Authentication and Registration Pages:

  • Scaffolded the identity login page (Login.cshtml and Login.cshtml.cs) that supports local and external authentication, including username/password login, "remember me" functionality, and error handling. [1] [2]
  • Scaffolded the identity registration page (Register.cshtml and Register.cshtml.cs) that collects email, username, first name, last name, and password, validates input, and supports external authentication. Registration sends a confirmation email and supports immediate sign-in or confirmation flow. [1] [2]

Custom User Model Integration:

  • Updated ApplicationDbContext to inherit from IdentityDbContext<ApplicationUser>, and configured the FirstName and LastName properties to be required and have a maximum length of 50 characters.

The `DefaultConnection` string in the `ConnectionStrings` section
of the `appsettings.json` file was updated. The database name was
changed
…ntity management

Updated ApplicationDbContext to use ApplicationUser instead of
IdentityUser, enabling a custom user model. Modified Program.cs
to configure identity services with ApplicationUser and
ApplicationDbContext. Updated _LoginPartial.cshtml to use
SignInManager and UserManager with ApplicationUser.
Introduced `FirstName` and `LastName` properties to the `ApplicationUser` model.
Added constraints to enforce a maximum length of 50 characters and marked these fields as required.

Created migrations `20251003175158_CustomizeUser` and `20251003175653_AddedNameLength` to update the database schema:
- Added `FirstName` and `LastName` columns to the `AspNetUsers` table.
- Updated column definitions to enforce length constraints.

Updated `ApplicationDbContextModelSnapshot` and related designer files to reflect these changes.
Adopted modern EF Core conventions and annotations for improved maintainability.
Enhanced the registration form and logic to include new fields:
- Added `Username`, `FirstName`, and `LastName` input fields in `Register.cshtml` with validation and labels.
- Changed `Email` input's `autocomplete` attribute to `email`.
- Introduced new properties (`Username`, `FirstName`, `LastName`) in `Register.cshtml.cs` with appropriate validation attributes.
- Updated user creation logic to:
  - Use `Username` instead of `Email` for `SetUserNameAsync`.
  - Populate `FirstName` and `LastName` during registration.
The default identity system made Email and Username the same during registration. The login expected an email as the username. This has issue has been addressed
@JoeProgrammer88 JoeProgrammer88 merged commit fbb2f73 into main Oct 3, 2025
1 check passed
@JoeProgrammer88 JoeProgrammer88 deleted the CustomizeIdentityUser branch October 3, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant